/*
* Task1Calculator
*
* r2
*
* GNU General Public License v3.0
*/

package com.acme;

// TODO: [VY] Please, move message to final static field.
public class Task1Calculator {
	private final static String errorMessage = "Error:";
	private final static String argsError = "Enter more args";
	private final static String operationError = "Invalid operation";
	private final static String firstNumberError = "First number is invalid";
	private final static String secondNumberError = "Second number is invalid";

	private static void error(String str) {
		System.out.println(errorMessage + str);
		System.exit(0);
	}
	
	public static void main(String[] args)
	{
		double arg0 = 0.0, arg1 = 0.0;
		
		// Check input
		if(args.length < 3) {
			error(argsError);
		}
		if(args[1].length() != 1) {
			error(operationError);
		}
		
		// Convert values
		try {
			arg0 = Double.parseDouble(args[0]);
		} catch (Exception ex) {
			error(firstNumberError);
		}
		try {
			arg1 = Double.parseDouble(args[2]);
		} catch (Exception ex) {
			error(secondNumberError);
		}
		
		// Process expression
		switch(args[1].charAt(0)) {
			case '+':
				System.out.println(arg0 + arg1);
				break;
			case '-':
				System.out.println(arg0 - arg1);
				break;
			case '*': // * is buggy
			case 'x': // so add "x"
				System.out.println(arg0 * arg1);
				break;
			case '\\':
				System.out.println(arg0 / arg1);
				break;
			default:
				error("Invalid operation");
				break;
		}
	}
}
